package com.ants.boot.model;

import com.ants.boot.core.security.jwt.JwtTokenProvider;
import com.ants.boot.utils.Constants;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 蚂蚁会花呗
 * @date 2022/2/24 10:18
 */
public abstract class BaseController {

    /**
     * 获取用户名
     * @param request
     * @param jwtTokenProvider
     * @return
     */
    public String getUsername(HttpServletRequest request, JwtTokenProvider jwtTokenProvider){
        String username = jwtTokenProvider.getUserNameFromToken(request.getHeader(Constants.JWT_TOKEN_NAME));
        return username;
    }

    /**
     * 获取userId
     * @param request
     * @param jwtTokenProvider
     * @return
     */
    public Integer getUserId(HttpServletRequest request, JwtTokenProvider jwtTokenProvider){
        Integer userId = jwtTokenProvider.getUserIdFromToken(request.getHeader(Constants.JWT_TOKEN_NAME));
        return userId;
    }

}
